package cn.edu.sjtu.dfa;

public class Call extends Instruction {
	private RegisterList pl;
	private Register ret;
	private Register ref;
	private String func;
	
	public Call(RegisterList rl, Register ret, Register ref, String func) {
		this.pl = rl;
		this.ret = ret;
		this.ref = ref;
		this.func = func;
	}
	
	public RegisterList getRegisterList() {
		return pl;
	}
	
	public Register getReturnRegister() {
		return ret;
	}
	
	public Register getCallee() {
		return ref;
	}
	
	public String getFunction() {
		return func;
	}

	@Override
	public String toString() {
		StringBuffer ret = new StringBuffer("Call: ");
		if (ref != null) {
			ret.append("v");
			ret.append(ref.getRegister());
			ret.append(".");
		}
		ret.append(func);
		ret.append("(");
		
		for (int i = 0; i < pl.size(); i++) {
			Register r = pl.elementAt(i);
			if (i > 0) {
				ret.append(",");
			}
			ret.append("v");
			ret.append(r.getRegister());
		}
		
		ret.append(")");
		return ret.toString();
	}
}
